<?php


namespace App\Models;
use Illuminate\Database\Eloquent\Model;


class PetStoreProductAttrResult extends Model
{
    protected $table = 'pet_store_product_attr_result';

    public static function setResult($result, $product_id, $type = 0)
    {
        $result = self::setResultAttr($result);
        $change_time = self::setChangeTimeAttr(0);

//        $count = self::where('product_id', $product_id)->where('type', $type)->count();
        $res = true;
//        if ($count) $res = self::where('product_id', $product_id)->where('type', $type)->delete();
        if ($res) return self::save(compact('product_id', 'result', 'change_time', 'type'), true);
        return $res;
    }

    protected static function setResultAttr($value)
    {
        return is_array($value) ? json_encode($value) : $value;
    }

    protected static function setChangeTimeAttr($value)
    {
        return time();
    }



}
